import 'package:dio/dio.dart';
import 'package:flutter_ebook/utils/log_utils.dart';

class PrintLogInterceptor implements InterceptorsWrapper {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    // 打印请求信息
    LogUtils.println("\nonRequest:-------------------------->");
    options.headers.forEach((key, value) {
      LogUtils.println("headers:key=$key,value=${value.toString()}");
    });
    LogUtils.println("url=${options.uri.toString()}");
    LogUtils.println("method=${options.method}");
    LogUtils.println("data=${options.data.toString()}");
    LogUtils.println("queryParameters=${options.queryParameters.toString()}");
    LogUtils.println("<--------------------------onRequest\n");
    // super.onRequest(options, handler);
  }

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) {
    LogUtils.println("onError:---------->");
    LogUtils.println("type=${err.type.toString()}");
    LogUtils.println("message=${err.message.toString()}");
    LogUtils.println("stackTrace=${err.stackTrace.toString()}");
    LogUtils.println("<----------onError\n");
    // super.onError(err, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    LogUtils.println("onResponse:---------->");
    LogUtils.println("statusCode=${response.statusCode}");
    LogUtils.println("headers=${response.headers.toString()}");
    LogUtils.println("data=${response.data.toString()}");
    LogUtils.println("<----------onResponse\n");
    // super.onResponse(response, handler);
  }
}
